<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button>点击</button>
    <script>
      var that;
      class Star {
        constructor(uname, age) {
          //  constructor 里面的this 指向的是 创建的实例对象
          that = this;
          this.uname = uname;
          this.age = age;
          //   this.sing();
          this.btn = document.querySelector("button");
          this.btn.onclick = this.sing;
        }
        sing() {
          console.log(that.uname);
        }
        dance() {
          console.log(this);
        }
      }
      var ldh = new Star("刘德华");
      ldh.dance();
      //在ES6中类没有变量提升，所以必须先定义类，才能通过类实例化对象
      // 类里面的共用属性和方法一定要加this使用
    </script>
  </body>
</html>
